<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var reverse = function(x) {
            if(x>0){
                let nums=[]
                var xs = x.toString()
                for(var i = xs.length-1; i>=0;i--){
                    nums = nums+xs[i]
                }
                var xss = Number(nums)
                if(xss>Math.pow(2,31)-1){
                    return 0
                }
                return xss
            }
            else if(x==0){
                return 0
            }
            else if (x<0){
                var number = Math.abs(x)
                let nums=[]
                var xs = number.toString()
                for(var i = xs.length-1; i>=0;i--){
                    nums = nums+xs[i]
                }
                nums = '-' + nums
                var xss = Number(nums)
                if(xss<Math.pow(-2,31)){
                    return 0
                }
                return xss
            }
        };
        var x = Number(-1230);
        console.log(reverse(x));
    </script>
</body>
</html>